//
//  HomeCell.m
//  GuShiNews
//
//  Created by 丁一 on 2019/8/17.
//  Copyright © 2019 Jones. All rights reserved.
//

#import "HomeCell.h"
#import "LunTanModel.h"
#import "HomeImgView.h"
#import "XLPhotoBrowser.h"

@interface HomeCell ()

@property (nonatomic, strong) UILabel *Label_tittle;

@property (nonatomic, strong) UIImageView *User_logo;
@property (nonatomic, strong) UILabel *User_name;
@property (nonatomic, strong) UILabel *Label_type;

@property (nonatomic, strong) UILabel *Label_bottom;

@property (nonatomic, strong) UILabel *Label_count;

@property (nonatomic, strong) CALayer *News_line;

@property (nonatomic, strong) HomeIMGView *Img_view;

@end

@implementation HomeCell

+ (instancetype)cellForTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *ID = @"HomeCell";
    HomeCell  *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell){
        cell=[[HomeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        cell.backgroundColor=[UIColor whiteColor];
        tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
        [cell setSelectionStyle:UITableViewCellSelectionStyleDefault];
        
        [cell.contentView addSubview:cell.Label_tittle];
        [cell.contentView addSubview:cell.User_logo];
        [cell.contentView addSubview:cell.User_name];
        [cell.contentView addSubview:cell.Label_type];
        [cell.contentView addSubview:cell.Label_bottom];
        [cell.contentView addSubview:cell.Label_count];
        [cell.contentView addSubview:cell.Img_view];
        [cell.contentView.layer addSublayer:cell.News_line];
    }
    
    return cell;
}

- (void)setModel:(LunTanModel *)Model{
    if (_Model != Model) {
        _Model = Model;
    }
    _Label_tittle.text = _Model.tittle;
    [_User_logo sd_setImageWithURL:[NSURL URLWithString:_Model.logo] placeholderImage:[UIImage imageNamed:@"user_logo.png"]];
    _User_name.text=_Model.name;
    _Label_bottom.text=_Model.info;
    _Label_type.text=[NSString stringWithFormat:@"#%@#",_Model.type];
    
    NSMutableString *linstr = [NSMutableString new];
    
    if ([_Model.zan_count intValue]>0) {
        [linstr appendString:[NSString stringWithFormat:@"%@赞  ",_Model.zan_count]];
    }
    if ([_Model.ping_count intValue]>0) {
        [linstr appendString:[NSString stringWithFormat:@"%@贴  ",_Model.ping_count]];
    }
    
    [linstr appendString:[JonesClass timeZhuan:_Model.date]];
    
    _Label_count.text=linstr;
    
    if (_Model.Img_array&&_Model.Img_array.count>0) {
        _Img_view.hidden = NO;
        [_Img_view setArray:_Model.Img_array];
        
        _Label_count.frame = CGRectMake(15, 125 + (RECRWITCH-40)/3+10, RECRWITCH-30, 30);
        _News_line.frame=CGRectMake(15, 159 + (RECRWITCH-40)/3+10, RECRWITCH-30, 1);
    }else{
        _Img_view.hidden = YES;
        
        _Label_count.frame = CGRectMake(15, 125, RECRWITCH-30, 30);
        _News_line.frame=CGRectMake(15, 159, RECRWITCH-30, 1);
    }
}

-(HomeIMGView *)Img_view{
    if (!_Img_view) {
        __weak typeof (self) weakSelf = self;
        _Img_view=[[HomeIMGView alloc] initWithFrame:CGRectMake(0, 130, RECRWITCH, (RECRWITCH-40)/3)];
        _Img_view.selectimg = ^(NSInteger Type) {
            [weakSelf show_img:Type];
        };
    }
    return _Img_view;
}

-(void)show_img:(NSInteger)no_type{
    XLPhotoBrowser *browser = [XLPhotoBrowser showPhotoBrowserWithImages:_Model.Img_array currentImageIndex:no_type];
    browser.seletBlock = ^(BOOL tui_ok) {
        
    };
}

-(UILabel *)Label_tittle{
    if (!_Label_tittle) {
        _Label_tittle           = [[UILabel alloc] init];
        _Label_tittle.font      = [UIFont boldSystemFontOfSize:18];
        _Label_tittle.textColor = NewsTitleColor;
        _Label_tittle.frame=CGRectMake(15, 10, RECRWITCH-30, 30);
        _Label_tittle.text=@"减肥的恐惧感刚看到房价过快递费放大镜看过";
    }
    return _Label_tittle;
}

-(UIImageView *)User_logo{
    if (!_User_logo) {
        _User_logo                     = [[UIImageView alloc] init];
        _User_logo.layer.masksToBounds = YES;
        _User_logo.layer.cornerRadius  = 12.5;
        _User_logo.contentMode         = UIViewContentModeScaleAspectFill;
        _User_logo.backgroundColor = backColor;
        _User_logo.frame=CGRectMake(15, 50, 25, 25);
        [_User_logo sd_setImageWithURL:[NSURL URLWithString:@"https://pics7.baidu.com/feed/94cad1c8a786c917ea4cc8a9ec9722ca3ac75706.jpeg?token=d7b89c9f3591aa91417d4a336aef0aed&s=A5B85795D0607D03185F59D9030070BF"]];
    }
    return _User_logo;
}

-(UILabel *)User_name{
    if (!_User_name) {
        _User_name           = [[UILabel alloc] init];
        _User_name.font      = [UIFont systemFontOfSize:13];
        _User_name.textColor = NewsinfoColor;
        _User_name.frame = CGRectMake(50, 50, RECRWITCH/2-20, 25);
        _User_name.text=@"司徒久";
    }
    return _User_name;
}

-(UILabel *)Label_type{
    if (!_Label_type) {
        _Label_type           = [[UILabel alloc] init];
        _Label_type.font      = [UIFont systemFontOfSize:13];
        _Label_type.textColor = NavItemTitleColor;
        _Label_type.textAlignment=NSTextAlignmentRight;
        _Label_type.frame = CGRectMake(RECRWITCH-150, 50, 135, 25);
        _Label_type.text=@"#海尔股份#";
    }
    return _Label_type;
}

-(UILabel *)Label_bottom{
    if (!_Label_bottom) {
        _Label_bottom           = [[UILabel alloc] init];
        _Label_bottom.font      = [UIFont systemFontOfSize:15];
        _Label_bottom.textColor = NewsinfoColor;
        _Label_bottom.numberOfLines = 2;
        _Label_bottom.frame = CGRectMake(15, 85, RECRWITCH-30, 40);
        _Label_bottom.text=@"科技 9 点见：传三星代工高通5G芯片大量报废 拼多多发布Q2财报";
    }
    return _Label_bottom;
}

-(UILabel *)Label_count{
    if (!_Label_count) {
        _Label_count           = [[UILabel alloc] init];
        _Label_count.font      = [UIFont systemFontOfSize:14];
        _Label_count.textColor = NewsotherColor;
        _Label_count.frame = CGRectMake(15, 125, RECRWITCH-30, 30);
        _Label_count.text=@"190 赞同 · 500 评论 · 6小时前";
    }
    return _Label_count;
}

- (CALayer *)News_line{
    if (!_News_line) {
        _News_line = [[CALayer alloc] init];
        _News_line.frame=CGRectMake(15, 159, RECRWITCH-30, 1);
        _News_line.backgroundColor=LineColor.CGColor;
    }
    return _News_line;
}


@end
